package com.wwp.tbshop.activity;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wwp.tbshop.R;
import com.wwp.tbshop.event.SaleNewsCartEventbus;
import com.wwp.tbshop.model.adapter.HotProductRVadapter;
import com.wwp.tbshop.model.bean.HotProductBean;
import com.wwp.tbshop.presenter.HotProductPresenter;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by ${wenping} on 6/16/2017.
 */

public class HotProductsActivity extends BaseActivity {

    @Bind(R.id.hot_products_loading)
    RelativeLayout mHotProductsLoading;
    @Bind(R.id.hot_products_back)
    ImageView mHotProductsBack;
    @Bind(R.id.hot_products_cart)
    ImageView mHotProductsCart;
    @Bind(R.id.hot_products_count_time)
    TextView mHotProductsCountTime;
    @Bind(R.id.hot_products_recycleview)
    RecyclerView mHotProductsRecycleview;
    private HotProductRVadapter mHotProductRVadapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_hot_products;
    }

    @Override
    protected void init() {
        super.init();
        HotProductPresenter mHotProductPresenter = new HotProductPresenter(this);
        mHotProductPresenter.loadHotProductInfo();
        mHotProductsRecycleview.setLayoutManager(new GridLayoutManager(this,2));
        mHotProductRVadapter = new HotProductRVadapter(this, this);
        mHotProductsRecycleview.setAdapter(mHotProductRVadapter);

    }

    public void onHotProductSuccess(List<HotProductBean.ProductListBean> list) {
        mHotProductRVadapter.setProductListBeanList(list);
    }

    @OnClick({R.id.hot_products_back,R.id.hot_products_cart})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.hot_products_back:
                finish();
                break;
            case R.id.hot_products_cart:
                //跳转到购物车;有问题呢;
                SaleNewsCartEventbus eventbus = new SaleNewsCartEventbus();
                eventbus.SalenewsToMain(this);
                EventBus.getDefault().post(eventbus);
                break;

        }
    }
}
